package com.gitee.huanminabc.fastboot.load.stage;

import com.gitee.huanminabc.jcommon.test.TaskTimeWatch;
import com.gitee.huanminabc.fastboot.context.AppContext;
import com.gitee.huanminabc.fastboot.load.hook.AppLoadFinishLifecycleHook;
import lombok.extern.slf4j.Slf4j;

/**
 * @program: netty-web
 * @description:
 * @author: huanmin
 * @create: 2025-04-01 10:47
 **/
@Slf4j
public class AppLoadStageFactory {

    //运行
    public static void start() {
        //启动一个初始化的线程
        Thread thread = new Thread(() -> {
            try {
                //项目内置配置加载
                new PreStageLauncher().load();
                //同步阶段
                new SyncStageLauncher().load();
                //容器加载完后执行post阶段
                new PostStageLauncher().load();
                //  应用加载完成事件
                new AppLoadFinishLifecycleHook().run();
                log.debug("资源加载完成耗时统计:{}",  AppContext.taskTimeWatch.prettyPrint());
                AppContext.projectLoadOk = true;
                log.debug("App load finished");
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                System.exit(1);
            }
        });
        thread.setDaemon(true);
        thread.start();

    }

}
